package com.work.xxzl.module.pagemine;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.work.xxzl.R;
import com.work.xxzl.base.BaseActivity;
import com.work.xxzl.cache.Ckey;
import com.work.xxzl.cache.SPutils;
import com.work.xxzl.module.main.MainActivity;
import com.work.xxzl.utils.UIUtils;
import com.work.xxzl.utils.VerificationUtil;
import com.work.xxzl.utils.ViewUtils;

import butterknife.BindView;


/**
 * author: Aly
 * date :2018/11/5 11:50
 * version:1.0
 * description:登陆页面
 */
public class LoginActivity extends BaseActivity {

    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.et_password)
    EditText etPassword;
    @BindView(R.id.bt_login)
    TextView btLogin;
    @BindView(R.id.tv_forgetpassword)
    TextView tvForgetpassword;
    @BindView(R.id.tv_newuser)
    TextView tvNewuser;
    @BindView(R.id.iv_zhifubao)
    ImageView ivZhifubao;
    @BindView(R.id.iv_weixin)
    ImageView ivWeixin;
    @BindView(R.id.iv_qq)
    ImageView ivQq;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_pagemine_login;
    }

    @Override
    protected void initView() {
        mTitleBar.titleMiddle.setText("登陆");
        ViewUtils.setOnClickListeners(this, btLogin, tvForgetpassword, tvNewuser, ivZhifubao, ivWeixin, ivQq);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void processClick(View v) {
        super.processClick(v);
        switch (v.getId()) {
            case R.id.bt_login:
                //登陆
                HideKeyboard(etPhone);
                if (VerificationUtil.isPhone(etPhone.getText().toString()) && VerificationUtil.isPassword(etPassword.getText().toString())) {
                    showLoaddialog("正在登陆");
                    UIUtils.getHandler().postDelayed(new Runnable() {
                        public void run() {
                            //execute the task
                            SPutils.put(Ckey.TOKEN, etPhone.getText().toString());
                            hideLoaddialog();
                            UIUtils.startActivity(MainActivity.class);
                            finish();
                        }
                    }, 800);
                }
                break;
            case R.id.tv_forgetpassword:
                //忘记密码
                UIUtils.startActivity(ForgetPasswordActivity.class);
                break;
            case R.id.tv_newuser:
                //新用户注册
                UIUtils.startActivity(RegisterActivity.class);
                break;
            case R.id.iv_zhifubao:
                //支付宝登陆
                UIUtils.startActivity(BindPhoneActivity.class);
                break;
            case R.id.iv_weixin:
                //微信登陆
                UIUtils.startActivity(BindPhoneActivity.class);
                break;
            case R.id.iv_qq:
                //QQ登陆
                UIUtils.startActivity(BindPhoneActivity.class);
                break;
        }
    }
}
